package com.newenergy.wisehome.ui.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.newenergy.wisehome.R;
import com.newenergy.wisehome.common.helper.SPUtil;
import com.newenergy.wisehome.config.AppManager;
import com.newenergy.wisehome.config.Constants;
import com.newenergy.wisehome.data.bean.DeviceCategory;

import butterknife.BindView;
import butterknife.OnClick;
import me.yokeyword.fragmentation.ISupportFragment;

/**
 *
 * Created by kyx on 2018/10/17.
 */

public class NewBathHeaterFragment extends BaseFragment {

    private static String ARG_NEW_BATHHEATER = "arg_new_bathheater";
    protected DeviceCategory mDeviceCategory;
    @BindView(R.id.btn_back)
    Button mBtnBack;
    @BindView(R.id.tv_back)
    TextView mTvBack;
    @BindView(R.id.tv_page)
    TextView mTvPage;
    @BindView(R.id.btn_lighting)
    Button mBtnLighting;
    @BindView(R.id.btn_swing)
    Button mBtnSwing;
    @BindView(R.id.btn_warm1)
    Button mBtnWarm1;
    @BindView(R.id.btn_warm2)
    Button mBtnWarm2;
    @BindView(R.id.btn_exchange_air)
    Button mBtnExchangeAir;
    @BindView(R.id.btn_blow_air)
    Button mBtnBlowAir;



    @Override
    public int getLayoutId() {
        return R.layout.fragment_new_bathheater;
    }


    public static ISupportFragment newInstance(DeviceCategory mainItem) {
        Bundle args = new Bundle();
        args.putParcelable(ARG_NEW_BATHHEATER, mainItem);
        NewBathHeaterFragment fragment = new NewBathHeaterFragment();
        fragment.setArguments(args);
        return fragment;

    }


    @Override
    public void init(View rootView) {
        mDeviceCategory = getArguments().getParcelable(ARG_NEW_BATHHEATER);

       /* if (mDeviceCategory != null) {
            Log.e("LFX", mDeviceCategory.toString());
        }*/
    }


    @Override
    public void onResume() {
        super.onResume();
        if (mDeviceCategory != null) {
            AppManager.getInstance(getContext()).mSelectDeviceCategory = mDeviceCategory;
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mDeviceCategory = null;
    }



    @OnClick({R.id.btn_back, R.id.tv_back, R.id.btn_lighting, R.id.btn_swing, R.id.btn_warm1, R.id.btn_warm2, R.id.btn_exchange_air, R.id.btn_blow_air})
    public void onViewClicked(View view) {
        boolean isOn;
        switch (view.getId()) {
            case R.id.btn_back:
                doBack();

                break;
            case R.id.tv_back:
                doBack();

                break;
            case R.id.btn_lighting://照明
                isOn= SPUtil.getBool(Constants.ISONNEWBATHHEATERLIGHT, false);
                if (isOn) {//如果开了就发关
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"02000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = false;

                } else  {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"02010000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = true;

                }
                SPUtil.put(Constants.ISONNEWBATHHEATERLIGHT,isOn);
                break;


            case R.id.btn_swing://摇摆
                isOn = SPUtil.getBool(Constants.ISONNEWBATHHEATERSWING, false);
                if (isOn) {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"07000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = false;
                } else  {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"07400000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = true;

                }
                SPUtil.put(Constants.ISONNEWBATHHEATERSWING,isOn);
                break;


            case R.id.btn_warm1://取暖1
                isOn = SPUtil.getBool(Constants.ISONNEWBATHHEATERWARM1, false);
                if (isOn) {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"05000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = false;
                } else  {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"05040000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = true;

                }
                SPUtil.put(Constants.ISONNEWBATHHEATERWARM1,isOn);
                break;


            case R.id.btn_warm2://取暖2
                isOn = SPUtil.getBool(Constants.ISONNEWBATHHEATERWARM2, false);
                if (isOn) {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"06000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = false;
                } else  {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"06100000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = true;

                }
                SPUtil.put(Constants.ISONNEWBATHHEATERWARM2,isOn);
                break;


            case R.id.btn_exchange_air://换气
                isOn = SPUtil.getBool(Constants.ISONNEWBATHHEATEREXAIR, false);
                if (isOn) {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"04000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = false;
                } else  {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"04200000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = true;

                }
                SPUtil.put(Constants.ISONNEWBATHHEATEREXAIR,isOn);
                break;


            case R.id.btn_blow_air://吹风
                isOn = SPUtil.getBool(Constants.ISONNEWBATHHEATERBLOWAIR, false);
                if (isOn) {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"03000000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = false;
                } else  {
                    AppManager.getInstance(mainActivity).commandAdvertise("01",mDeviceCategory.getFamilyId(),mDeviceCategory.getGroupId(),"03020000","000000",mCurrFamily.getSeed(),mCurrFamily.getFeedback(),1,"7205");
                    isOn = true;

                }
                SPUtil.put(Constants.ISONNEWBATHHEATERBLOWAIR,isOn);

                break;
        }
    }
}
